package graphics;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.util.List;


public class SparkParticle extends Particle{
	
	int incx, incy;

	public SparkParticle(int x, int y, int dx, int dy) {
		super(x, y, dx, dy);
		spdx = -dx/(2+rnd.nextInt(5));
		spdy = -dy/(2+rnd.nextInt(5));
		lifetime = 15+rnd.nextInt(10);
		imageName = "Spark2.png";
		particleSize = 12000;
		incx = -20+rnd.nextInt(40);
		incy = -20+rnd.nextInt(40);
	}
	
	public void nextFrame(List<Particle> pList){
		lifetime--;
		if(isDead())
			pList.remove(this);
		posx = posx + spdx;
		posy = posy + spdy;
		spdy=spdy+incy;
		spdx=spdx+incx;
	}

	public void paint(Point screenOffset, int zoomDivider, Graphics g){
		BufferedImage im = (BufferedImage)ImageHandler.getInstance().getImage(imageName);
		Graphics2D g2d = (Graphics2D)g;
		AffineTransform at = new AffineTransform();
		at.translate((posx-particleSize/2-screenOffset.x)/zoomDivider, (posy-particleSize/2-screenOffset.y)/zoomDivider);
		at.scale((double)particleSize/im.getWidth()/zoomDivider, (double)particleSize/3/im.getHeight()/zoomDivider);
		double dir = Math.atan2(spdy, spdx);
		at.rotate(dir, im.getWidth()/2, im.getHeight()/2);

		
		
		g2d.drawImage(im, at, ImageHandler.getInstance());
	}
	
}
